<?php

namespace Modules\Car\Http\Controllers;

use App\Helpers\ResponseData;
use App\Models\Car;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Carbon;
use Modules\Car\Entities\ForbidLeaseDate;
use Modules\Car\Entities\RecognizeDrivingLicense;

class CarController extends Controller
{
    use ResponseData;
    public function index(Request $request){
        $month = now()->format('Ym');
        $car_series_id = 83;
        $data = $this->searchForbitSeries($month,$car_series_id);
        $array_cars = $this->searchSeriesCars($car_series_id);
        sort($array_cars);
        $result = [];
        dump($array_cars);
        foreach ($data as $key=>$value){
            $second[]= $value;
            $arr = array_column($second,'car_id');
            sort($arr);
            if($array_cars==$arr){
                $result[]=$value['non_lease_date'];
            }
        }
        dd($result);
    }

    //获取不可用车系id array
    protected function searchForbitSeries($month,$car_series_id){
        $cars = ForbidLeaseDate::query()
            ->select('car_id','forbid_date','non_lease_date')
            ->where('month',$month)
            ->where('car_series_id',$car_series_id)
            ->groupBy('forbid_date')->get()->toArray();
        return $cars;
    }
    //获取该车系下所有车辆
    protected function searchSeriesCars($car_series_id){
        return RecognizeDrivingLicense::query()
            ->where('car_series_id',$car_series_id)
            ->pluck('id')->toArray();
    }

   public function search(Request $request,Car $car){

//       $data = $car->query()->where('license','like','%'.$request->license.'%')->get();
//       return $this->success($data);
   }
}
